package com.bnz.controller;

import com.bnz.entity.Student;
import com.bnz.entity.vo.StudentVo;
import com.bnz.service.StudentService;
import com.bnz.util.PageResult;
import com.bnz.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController // 注入spring荣日,将java对象转为json格式
@RequestMapping("stu")
public class StudentController {
    // 引入service
    @Autowired // 根据类型，从spring容器中拿bean
    private StudentService studentService;

    // 1、查询所有数据
    @GetMapping("list")
    public R findAll(){
        // 1.1、创建查询方法
        List<Student> all = studentService.findAll();
        return R.ok().data("list",all); // "list"前端的参数
    }

    // 2、条件查询带分页
    @PostMapping("search")
    //  @RequestBody 将前端的json串转换为java对象
    public R search(int page, int pagesize, @RequestBody StudentVo studentVo){
        PageResult<Student> search = studentService.search(page, pagesize, studentVo);
        return R.ok().data("pr",search);
    }

}
